package com.janushuang.algorithm.sorter;

/**
 * @author zhijing.huang
 *         Created by zhijing.huang on 2014/9/26.
 */
public class SelectionSorter<E extends Comparable<E>> extends Sorter<E> {
    @Override
    public void sort(E[] data, int from, int len) {
        for (int i = from; i < from+len; i++) {
            int smallest = i;

            for ( int j = i;j<from+len;j++) {
                if (data[j].compareTo(data[smallest])<0) {
                    smallest = j;
                }
            }
            swap(data,i,smallest);
        }
    }

//    @Override
//    public void sort(int[] data) {
//        for (int i = 0; i < data.length; i++) {
//            int lowIndex = i;
//            for (int j = data.length-1; j > i; j--) {
//                if (data[j] < data[lowIndex]) {
//                    lowIndex = j;
//                }
//            }
//            SortUtils.swap(data,i,lowIndex);
//        }
//    }
}
